package com.sservice.commonBusiness.controller.admin;

import com.sservice.base.entity.dto.BaseResult;
import com.sservice.base.entity.dto.ListResult;
import com.sservice.base.entity.dto.Pagination;
import com.sservice.commonBusiness.e.Comment;
import com.sservice.commonBusiness.mapper.CommentMapper;
import com.sservice.commonBusiness.service.CommentService;
import com.sservice.commonBusiness.vo.CommentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by byte_su@163.com on 2018/01/12.
 */
@Controller
@RequestMapping("/admin/comment/")
public class CommentController {

    @Autowired
    CommentService commentService;
    @Autowired
    CommentMapper commentMapper;

    @RequestMapping(value = "add", method = RequestMethod.POST)
    @ResponseBody
    public BaseResult add(Comment comment) {
        return new BaseResult(true, String.valueOf(commentService.insertSelective(comment)), 200);
    }

    @RequestMapping(value = "delete/{id}", method = RequestMethod.POST)
    @ResponseBody
    public BaseResult delete(Comment record) {
        return new BaseResult(true, String.valueOf(commentService.deleteByPrimaryKey(record.getId())), 200);
    }

    @RequestMapping(value = "update", method = RequestMethod.POST)
    @ResponseBody
    public BaseResult update(Comment comment) {
        return new BaseResult(true, String.valueOf(commentService.updateByPrimaryKeySelective(comment)), 200);
    }

    @RequestMapping("detail/{id}")
    @ResponseBody
    public BaseResult detail(@RequestParam Integer id) {
        Comment comment = commentService.selectByPrimaryKey(id);
        return new BaseResult(true, comment);
    }

    @RequestMapping("list")
    @ResponseBody
    public ListResult list(CommentVo commentVo) {
        List<CommentVo> list = commentMapper.page(commentVo);
        Pagination pagination = new Pagination();
        pagination.setTotal(commentMapper.pageCount(commentVo));
        ListResult lr = new ListResult(true, list);
        lr.setPage(pagination);
        return lr;
    }

    /**
     * 管理端评论内容
     *
     * @param commentVo
     * @return
     */
    @RequestMapping("userComments")
    @ResponseBody
    public ListResult userComments(CommentVo commentVo) {


        return commentService.userComment(commentVo);
    }
}
